package com.conferences.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.ModelAttribute;

import com.conferences.model.Conference;
import com.conferences.service.ConferenceService;
import com.conferences.service.UserService;

public class App {

	@Autowired
	UserService userService;

	@Autowired
	ConferenceService conferenceService;

	@ModelAttribute("user")
	public User getUser() {
		User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		return user;
	}

	@ModelAttribute("conferencesAll")
	public List<Conference> getConferences() {
		List<Conference> conferences = conferenceService.list();
		for (Conference conference : conferences) {
			conference.setAuthor(conference.getAuthor());
		}
		return conferences;
	}

}
